package gitee.derumin.teleport_compass;

import net.minecraft.util.math.GlobalPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class TCConfig {
    public int benefitsTimeRemains;
    public int benefitsCompassCount;
    public int benefitsLodestoneCount;
    public int baseTeleportCost;
    public float teleportCostDistanceMultiplier;
    public int extraTeleportCostCrossDimension;
    public int maxTeleportCost;
    public String costMode;
    public boolean internationalization;

     TCConfig(){
        this.benefitsTimeRemains = 24 *60 *60 *20;
        this.benefitsCompassCount = 2;
        this.benefitsLodestoneCount = 1;
        this.baseTeleportCost = 5;
        this.teleportCostDistanceMultiplier = 1.0f;
        this.extraTeleportCostCrossDimension = 5;
        this.maxTeleportCost = 100;
        this.costMode = "constant";
        this.internationalization = false;
    }

    public int getTeleportCost(Vec3d position, World world, GlobalPos target){
         this.maxTeleportCost = MathHelper.clamp(this.maxTeleportCost, 0, 65535);
         this.baseTeleportCost = MathHelper.clamp(this.baseTeleportCost, 0, this.maxTeleportCost);
         this.teleportCostDistanceMultiplier = MathHelper.clamp(this.teleportCostDistanceMultiplier, 0f, 256f);
         this.extraTeleportCostCrossDimension = MathHelper.clamp(this.extraTeleportCostCrossDimension, 0, 65535);
         int i = this.baseTeleportCost;
         double c;
         switch (this.costMode){
             case "distance" -> c = this.teleportCostDistanceMultiplier *Math.sqrt(target.pos().getSquaredDistanceFromCenter(position.x, position.y, position.z))/1000d;
             case "distanceSquared" -> c = this.teleportCostDistanceMultiplier *target.pos().getSquaredDistanceFromCenter(position.x, position.y, position.z)/1000000d;
             default -> {
                 c = 0;
                 if (!this.costMode.equals("constant")){
                     this.costMode = "constant";
                 }
             }
         }
         i += (int) c + (target.dimension().equals(world.getRegistryKey())? 0 : this.extraTeleportCostCrossDimension);
         i = Math.max(0, Math.min(i, this.maxTeleportCost));
         return i;
    }
}
